﻿<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="STYLESHEET" type="text/css" id="SkinStyleSheet">
<title>WebNoteEditor</title>
<style>
th{white-space:nowrap}
td.Preview{width:150px;text-align:center;overflow:hidden}
.Previewimg2{width:100px;height:100px}
#selectwaterscheme{
	width:180px
}
</style>
<script language="javascript" type="text/javascript" src="../script/windialog.js"></script>
<script language="javascript" type="text/javascript" src="../script/ie2w3c-min.js"></script>
<script language="javascript" type="text/javascript">

window.onload=function()
{
	EditorWindow.renderWindowAsIE(window);
	__loadData();

	var selwaterscheme;
	selwaterscheme=new EditorWindow._HTMLselect("selectwaterscheme",document);
	selwaterscheme.addOptionByXML("files/waterscheme/waterscheme.xml","rulestring","name");
	selwaterscheme=null;

	document.getElementById("btnOk").onclick=__btnOk_onclick;
	document.getElementById("btnResize").onclick=__btnResize_onclick;
	document.getElementById("btnDrawImage").onclick=__btnDrawImage_onclick;
	document.getElementById("btnResizeAndDragImage").onclick=__btnResizeAndDragImage_onclick;
	
	document.getElementById("btnSelectAll").onclick=function(){EditorWindow._FormCheckBoxSelectAll("checkboximage",document.getElementById("ViewFrm").contentWindow.document)};
	document.getElementById("btnUnSelectAll").onclick=function(){EditorWindow._FormCheckBoxUnSelectAll("checkboximage",document.getElementById("ViewFrm").contentWindow.document)};

	EditorWindow.renderWindowAsIE(document.getElementById("ViewFrm").contentWindow);
	AutoResizeDialogWindow();	
}

function __btnOk_onclick()
{
	window.returnValue=true;
	window.close();
}

function getImageInfo(srcElement)
{
	var elem;
	//elem=this;
	//var event=(window.event?document.getElementById("ViewFrm").contentWindow.event:event);
	//elem=event.srcElement;
	elem=srcElement

	if (elem.readyState=="complete" || !EditorWindow.$browser.isIE)
	{
		elem.removeAttribute("width");
		elem.removeAttribute("height");
		
		elem.parentNode.parentNode.cells[3].innerText=elem.clientWidth+"×"+elem.clientHeight;
		
		if (elem.clientHeight>100)
			elem.height=100;
		if (elem.clientWidth>100)
			elem.width=100;
		
		if (elem.fileSize!=undefined)
			elem.parentNode.parentNode.cells[2].innerText=EditorWindow.FileSizeToString(elem.fileSize);
	}

	elem=null;
}

function getClientDisplaySize(sIndex,sFileURL)
{
	//on error resume next
	//获得的当前编辑框中对应的图片的显示尺寸
	//alert(sFileURL)
	var i,j,pageCount,page,elems,firstPage;
	firstPage=EditorWindow.getAbsolutePage();
	currentPage=firstPage;
	pageCount=EditorWindow.getPageCount();
	for(page=1;page<=pageCount;page++)
	{
		elems=XEditor.document.getElementsByTagName("img");
		for (i=0;i<elems.length;i++)
		{
			//alert(elems[i].getAttribute("src")+"\n"+sFileURL);
			if (EditorWindow.getFileName(elems[i].getAttribute("src"),"/")==EditorWindow.getFileName(sFileURL,"/"))
			{
				//alert("match:"+elems[i].clientWidth+"×"+elems[i].clientHeight);
				document.getElementById("ViewFrm").contentWindow.document.getElementById(sIndex).parentNode.parentNode.cells[4].textContent=document.getElementById("ViewFrm").contentWindow.document.getElementById(sIndex).parentNode.parentNode.cells[4].innerText=elems[i].clientWidth+"×"+elems[i].clientHeight;

				return;
				break;
			}
		}
		elems=null;


		elems=XEditor.document.getElementsByTagName("imagedata");
		for (i=0;i<elems.length;i++)
		{
			//alert(elems[i].getAttribute("src")+"\n"+sFileURL);
			if (EditorWindow.getFileName(elems[i].getAttribute("src"),"/")==sFileURL)
			{
				document.getElementById("ViewFrm").contentWindow.document.getElementById(sIndex).parentNode.parentNode.cells[4].textContent=document.getElementById("ViewFrm").contentWindow.document.getElementById(sIndex).parentNode.parentNode.cells[4].innerText=elems[i].parentElement.clientWidth+"×"+elems[i].parentElement.clientHeight;

				return;
				break;
			}
		}
		elems=null;

		if (currentPage==pageCount)
		{
			currentPage=0;
			//alert("reset");
		}
		
		EditorWindow.gotoAbsolutePage(parseInt(currentPage)+1);
		currentPage=EditorWindow.getAbsolutePage();
		//alert("goto="+(parseInt(currentPage)+1));
	}
	document.getElementById("ViewFrm").contentWindow.document.getElementById(sIndex).parentNode.parentNode.cells[4].textContent=document.getElementById("ViewFrm").contentWindow.document.getElementById(sIndex).parentNode.parentNode.cells[4].innerText="0";
}



function __loadData()
{
	var i,pageCount;
	//pageCount=EditorWindow.getPageCount();
	var root;

	if (EditorWindow.$config.allow_viewallfiles)
	{
		__LoadFiles();
	}
	else
	{
		Url="../"+EditorWindow.$config.isapi+"/filebrowser_xml."+EditorWindow.$config.isapi+"\?act=1";
		createXMLDom(Url,"",onloadFolder);
	}
}

function __LoadFiles()
{
	var i,files,isImage,fs;
	files=EditorWindow.getAllFiles().split("|");
	var d=document.getElementById("ViewFrm").contentWindow.document;
	var rndName=EditorWindow.getAutoName();
	d.writeln("<table width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" align=\"center\" class=\"WebNote_DataList2\">");
	d.writeln("<tr>");
	d.writeln("<th align=\"center\" width=\"25px\"></th>");
	d.writeln("<th align=\"center\" style=\"display:none\">"+EditorWindow.lang_preview+"</th>");
	d.writeln("<th align=\"center\" width=\"80px\">"+EditorWindow.lang_filesize+"</th>");
	d.writeln("<th align=\"center\" width=\"100px\">"+EditorWindow.lang_realsize+"</th>");                       
	d.writeln("<th align=\"center\" width=\"100px\">"+EditorWindow.lang_displaysize+"</th>");
	d.writeln("<th align=\"center\" width=\"50px\">"+EditorWindow.lang_filetype+"</th>");
	d.writeln("<th align=\"center\" width=\"40px\">"+EditorWindow.lang_operate+"</th>");
	d.writeln("</tr>");

	var u=document.location.pathname.toString().replace("dialogs/dialogserverfiles.htm","");

	for(i=0;i<files.length;i++)
	{
		fileExName=EditorWindow.getFileExt(files[i]);
		fs=EditorWindow.getFileName(files[i]);
		if (EditorWindow.$config.allow_upload_file_ext.isInArray(fileExName))
		{
			if (files[i].indexOf(u)=="-1" && (files[i].indexOf("http")==0 || files[i].indexOf("/")==0))
			{
				isImage=EditorWindow.$config.allow_upload_image_ext.isInArray(fileExName);
		
				d.writeln("<tr>");
				d.writeln("<td align=\"center\">");
				if (isImage)
					d.writeln("<input id=\"checkboximage"+i+"\" name=\"checkboximage\" type=\"checkbox\" value=\""+files[i]+"\">"); 
				d.writeln("</td>");
				
				d.writeln("<td align=\"center\">");
				if (isImage)
				{
					d.writeln("<img firstsrc=\""+files[i]+"\" src=\""+files[i]+"?"+rndName+"\" onload=\"javascript:window.top.getImageInfo(this);\">"); 
				}
				else
				{
					if (EditorWindow.$config.word_image_file_ext.isInArray(fileExName))
					{
						d.writeln("<v:shape style=\"width:50px;height:50px\"><v:imagedata src=\""+files[i]+"\"></v:imagedata></v:shape>"); 
					}
					else
					{
						d.writeln("<img src=\"../images/filetype/"+fileExName+".gif\">"); 
					}
				}
				
				d.writeln("</td>");
	
				d.writeln("<td align=\"center\" style=\"display:none\">");
				d.writeln(fs);
				d.writeln("</td>");
	
				d.writeln("<td align=\"center\">");
				d.writeln("</td>");
	
				d.writeln("<td align=\"center\">");
				d.writeln("</td>");
	
				d.writeln("<td align=\"center\">"+fileExName);
				d.writeln("</td>");
	
				d.writeln("<td align=\"center\">");
				d.writeln("<a href=\"javascript:window.parent.__insertFile('"+files[i]+"');\">"+EditorWindow.lang_insert+"</a>");
				d.writeln("<v:shape></v:shape>"); 
				d.writeln("</td>");
				
				
				d.writeln("</tr>");
			}
		}
		
	}
	d.writeln("</table>");
	if(!document.createStyleSheet) 
	{ 
		var cssObj=document.createElement("link"); 
		cssObj.type="text/css";
		cssObj.rel="stylesheet";
		cssObj.href=document.getElementById("SkinStyleSheet").href;
		d.body.appendChild(cssObj); 
		cssObj=null;
	}
	else
	{
		d.createStyleSheet(document.getElementById("SkinStyleSheet").href);
	}
	
	//获取实际显示尺寸
	
	var firstPage=EditorWindow.getAbsolutePage();
	var i,elems;
	elems=d.getElementsByName("checkboximage");

	for (i=0;i<elems.length;i++)
	{
		getClientDisplaySize(elems[i].id,elems[i].value);
	}
	elems=null;
	d=null;
	EditorWindow.gotoAbsolutePage(firstPage);
}

function onloadFolder()
{
	var isReady=false;
	var root,folderpath;
	var i,elems,isImage;
	var d=document.getElementById("ViewFrm").contentWindow.document;
	var rndName=EditorWindow.getAutoName();
	if (EditorWindow.$browser.isIE)
	{
		if (xmlDom.readyState== 4)
			isReady=true;
		else
			return;
	}
	else
	{
		isReady=true;
	}
	if (isReady)
	{
		if (EditorWindow.$browser.isIE)
		{
			var err = xmlDom.parseError;
			if (err.errorCode!=0)
			{
				alert(err.reason);
				return;
			}
			else
			{
				root=xmlDom.documentElement;
			}
		}
		else
		{
			root=xmlDom.documentElement;
		}

		folderpath=unescape(root.getAttribute("folderpath"));
		errdescription=root.getElementsByTagName("errdescription")[0].firstChild.nodeValue;
		if (errdescription)
		{
			alert(errdescription);
			window.close();
		}
		
		elems=root.getElementsByTagName("files")[0].getElementsByTagName("file");


		d.writeln("<table width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" align=\"center\" class=\"WebNote_DataList2\">");
		d.writeln("<tr>");
		d.writeln("<th align=\"center\" width=\"25px\"></th>");
    	d.writeln("<th align=\"center\" >"+EditorWindow.lang_preview+"</th>");
		d.writeln("<th align=\"center\" width=\"80px\">"+EditorWindow.lang_filesize+"</th>");
		d.writeln("<th align=\"center\" width=\"100px\">"+EditorWindow.lang_realsize+"</th>");                       
		d.writeln("<th align=\"center\" width=\"100px\">"+EditorWindow.lang_displaysize+"</th>");
		d.writeln("<th align=\"center\" width=\"50px\">"+EditorWindow.lang_filetype+"</th>");
		d.writeln("<th align=\"center\" width=\"40px\">"+EditorWindow.lang_operate+"</th>");
		d.writeln("</tr>");
		
		for(i=0;i<elems.length;i++)
		{
		
			fn=elems[i].getElementsByTagName("filename")[0].firstChild.nodeValue;
			
			fs=EditorWindow.FileSizeToString(elems[i].getElementsByTagName("filesize")[0].firstChild.nodeValue);
			fileExName=EditorWindow.getFileExt(elems[i].getElementsByTagName("fileexname")[0].firstChild.nodeValue);
			
			if (EditorWindow.$config.allow_upload_file_ext.isInArray(fileExName))
			{
				isImage=EditorWindow.$config.allow_upload_image_ext.isInArray(fileExName);
			
				d.writeln("<tr>");
				d.writeln("<td align=\"center\">");
				if (isImage)
					d.writeln("<input id=\"checkboximage"+i+"\" name=\"checkboximage\" type=\"checkbox\" value=\""+fn+"\">"); 
				d.writeln("</td>");
				
				d.writeln("<td align=\"center\">");
				if (isImage)
				{
					d.writeln("<img firstsrc=\""+folderpath+"/"+fn+"\" src=\""+folderpath+"/"+fn+"?"+rndName+"\" onload=\"javascript:window.top.getImageInfo(this);\">"); 
				}
				else
				{
					if (EditorWindow.$config.word_image_file_ext.isInArray(fileExName))
					{
					d.writeln("<v:shape style=\"width:50px;height:50px\"><v:imagedata o:title=\"\" src=\""+folderpath+"/"+fn+"\"></v:imagedata></v:shape>");
					d.writeln("<v:shape></v:shape>"); 
					}
					else
					{
						d.writeln("<img src=\"../images/filetype/"+fileExName+".gif\">"); 
					}
				}
				
				d.writeln("</td>");

				d.writeln("<td align=\"center\">");
				d.writeln(fs);
				d.writeln("</td>");

				d.writeln("<td align=\"center\">");
				d.writeln("</td>");

				d.writeln("<td align=\"center\">");
				d.writeln("</td>");

				d.writeln("<td align=\"center\">"+fileExName);
				d.writeln("</td>");

				d.writeln("<td align=\"center\">");
				d.writeln("<a href=\"javascript:window.parent.__insertFile('"+folderpath+"/"+fn+"');\">"+EditorWindow.lang_insert+"</a>");
				d.writeln("</td>");
				
				
				d.writeln("</tr>");

			}
			
		}
		d.writeln("</table>");
		if(!document.createStyleSheet) 
	    { 
			var cssObj=document.createElement("link"); 
			cssObj.type="text/css";
			cssObj.rel="stylesheet";
			cssObj.href=document.getElementById("SkinStyleSheet").href;
			d.body.appendChild(cssObj); 
			cssObj=null;
	    }
	    else
	    {
	    	d.createStyleSheet(document.getElementById("SkinStyleSheet").href);
	    }
		elems=null;
	}
	//获取实际显示尺寸
	
	var firstPage=EditorWindow.getAbsolutePage();
	var i,elems;
	elems=document.getElementById("ViewFrm").contentWindow.document.getElementsByName("checkboximage");

	for (i=0;i<elems.length;i++)
	{
		getClientDisplaySize(elems[i].id,elems[i].value);
	}
	elems=null;
	EditorWindow.gotoAbsolutePage(firstPage);
}


function __insertFile(sFileUrl)
{
	EditorWindow.__insertFile(sFileUrl);
}


function __btnResize_onclick()
{
	var i,elems,root,returnvalue,errordescription;
	var tempStr,tempStr1;
	var displayWidth,displayHeight,realWidth,realHeight,resize2Width,resize2Height;
	elems=document.getElementById("ViewFrm").contentWindow.document.getElementsByName("checkboximage");
	document.getElementById("btnResize").disabled="disabled";
	for (i=0;i<elems.length;i++)
	{
		if (elems[i].checked)
		{
			
			if (elems[i].parentNode.parentNode.cells[4].innerText!="")
			{
				//display size
				tempStr=elems[i].parentNode.parentNode.cells[4].innerText.split("×");
				//real size
				tempStr1=elems[i].parentNode.parentNode.cells[3].innerText.split("×");	
				
				displayWidth=parseInt(tempStr[0]);
				displayHeight=parseInt(tempStr[1]);
				realWidth=parseInt(tempStr1[0]);
				realHeight=parseInt(tempStr1[1]);
				
				if (realWidth>displayWidth || realHeight>displayHeight)
				{
					//if resize to small size
					root=EditorWindow.__XMLHttpRequest(EditorWindow.$config.isapi+"/resizeimage."+EditorWindow.$config.isapi,"POST","filename="+elems[i].value+"&width="+displayWidth+"&height="+displayHeight,"xml");
					
					//return;
					returnvalue=root.getElementsByTagName("returnvalue")[0].firstChild.nodeValue;

					if (returnvalue=="true")
					{
						elems[i].parentNode.parentNode.cells[1].firstChild.src=elems[i].parentNode.parentNode.cells[1].firstChild.getAttribute("firstsrc")+"?"+EditorWindow.getAutoName();
						//alert(elems[i].parentElement.parentElement.children(1).firstChild.src);
					}
					else
					{
						errordescription=root.getElementsByTagName("errordescription")[0].firstChild.nodeValue;
						alert(errordescription);
					}
					elems[i].scrollIntoView();
				}
			}
		}
	}
	elems=null;
	document.getElementById("btnResize").disabled="";
}

function __btnDrawImage_onclick()
{
	var i,elems,root,returnvalue,errordescription;
	var tempStr,tempStr1;
	var displayWidth,displayHeight,realWidth,realHeight,resize2Width,resize2Height;
	elems=document.getElementById("ViewFrm").contentWindow.document.getElementsByName("checkboximage");
	document.getElementById("btnDrawImage").disabled="disabled";
	for (i=0;i<elems.length;i++)
	{

		if (elems[i].checked)
		{
			root=EditorWindow.__XMLHttpRequest(EditorWindow.$config.isapi+"/drawimage."+EditorWindow.$config.isapi,"POST","filename="+elems[i].value+"&rulestring="+document.getElementById("selectwaterscheme").value,"xml");
			//root=EditorWindow.__XMLHttpRequest(EditorWindow.$config.isapi+"/drawimage."+EditorWindow.$config.isapi,"POST","filename="+elems[i].value+"&rulestring="+document.getElementById("selectwaterscheme").value,"text");
			returnvalue=root.getElementsByTagName("returnvalue")[0].firstChild.nodeValue;
			if (returnvalue=="true")
			{
				//alert(elems[i].parentElement.parentElement.children(1).firstChild.src);
				elems[i].parentElement.parentElement.children(1).firstChild.src=elems[i].parentElement.parentElement.children(1).firstChild.getAttribute("firstsrc")+"?"+EditorWindow.getAutoName();
			}
			else
			{
				errordescription=root.getElementsByTagName("errordescription")[0].firstChild.nodeValue;
				alert(errordescription);
			}
			elems[i].scrollIntoView();
		}
	}
	elems=null;
	document.getElementById("btnDrawImage").disabled="";
}

function __btnResizeAndDragImage_onclick()
{
	document.getElementById("btnResizeAndDragImage").disabled="disabled";
	__btnResize_onclick()
	__btnDrawImage_onclick();
	document.getElementById("btnResizeAndDragImage").disabled="";

}

</script>
</head>

<body class="dialog">
<script language="javascript" type="text/javascript">dialogTitle("lang_viewuploadfiles");</script>
<iframe id="ViewFrm" style="width:100%;height:400px" frameborder="no" scrolling="yes"></iframe>

<div style="text-align:center;width:100%" class="hr">
		<script type="text/javascript" language="javascript">
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_button_selectall+"\" id=\"btnSelectAll\" class=\"SysBtn5\">");
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_button_unselectall+"\" id=\"btnUnSelectAll\" class=\"SysBtn5\">");
		</script>
		<hr size="1" color="#B3AC9D">
		
		<script type="text/javascript" language="javascript">
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_fitdisplaysize+"\" class=\"SysBTN\" id=\"btnResize\">");
		</script>
		<select id="selectwaterscheme"></select>

		<script type="text/javascript" language="javascript">
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_watermark+"\" class=\"SysBTN\" id=\"btnDrawImage\">");
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_fitdisplaysizeandwatermark+"\" class=\"SysBTN\" id=\"btnResizeAndDragImage\">");
		</script>
</div>

<div class="alerttext"><script type="text/javascript" language="javascript">dialogPrintlang("lang_tips50");</script></div>

<div style="text-align:right;padding-right:20">
		<script type="text/javascript" language="javascript">
			document.write("<input type=\"button\" value=\""+EditorWindow.lang_button_ok+"\" class=\"SysBTN5\" id=\"btnOk\" tabindex=\"1\">");
		</script>
</div>

<!--
<img id="imgPreView" style="display:none;" alt="">
-->
</body>  
  
</html>
